# Copyright 2010-2025 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Utilities to load native libraries in java or-tools.
cc_binary(
    name = "libjniortools.so",
    linkshared = True,
    target_compatible_with = select({
        "@platforms//os:linux": [],
        "//conditions:default": ["@platforms//:incompatible"],
    }),
    visibility = ["//visibility:public"],
    deps = [
        "//ortools/algorithms/java:knapsacksolver_cc",
        "//ortools/graph/java:graph_cc",
        "//ortools/init/java:init_cc",
        "//ortools/linear_solver/java:modelbuilder_cc",
        "//ortools/sat/java:sat_cc",
        "//ortools/util/java:sorted_interval_list_cc",
    ],
)

cc_binary(
    name = "libjniortools.dylib",
    linkshared = True,
    target_compatible_with = select({
        "@platforms//os:osx": [],
        "//conditions:default": ["@platforms//:incompatible"],
    }),
    visibility = ["//visibility:public"],
    deps = [
        "//ortools/algorithms/java:knapsacksolver_cc",
        "//ortools/graph/java:graph_cc",
        "//ortools/init/java:init_cc",
        "//ortools/linear_solver/java:modelbuilder_cc",
        "//ortools/sat/java:sat_cc",
        "//ortools/util/java:sorted_interval_list_cc",
    ],
)

cc_binary(
    name = "jniortools.dll",
    linkshared = True,
    target_compatible_with = select({
        "@platforms//os:windows": [],
        "//conditions:default": ["@platforms//:incompatible"],
    }),
    visibility = ["//visibility:public"],
    deps = [
        "//ortools/algorithms/java:knapsacksolver_cc",
        "//ortools/graph/java:graph_cc",
        "//ortools/init/java:init_cc",
        "//ortools/linear_solver/java:modelbuilder_cc",
        "//ortools/sat/java:sat_cc",
        "//ortools/util/java:sorted_interval_list_cc",
    ],
)

java_library(
    name = "Loader",
    srcs = ["Loader.java"],
    visibility = ["//visibility:public"],
    runtime_deps = select({
        "@platforms//os:linux": ["//ortools/java/com/google/ortools:libjniortools.so"],
        "@platforms//os:osx": ["//ortools/java/com/google/ortools:libjniortools.dylib"],
        "@platforms//os:windows": ["//ortools/java/com/google/ortools:jniortools.dll"],
    }),
    deps = [
        "@maven//:net_java_dev_jna_jna",
    ],
)
